1Writer ルーチン化 1.0.0
1Writer ルーチン化 1.0.1
⚠️ルーチン位置を選択する必要があり面倒。時刻ベースで位置が決まるTaskChute CloudやTaskChute Cloud 2は実行時刻ベースでルーチン位置が一発で決まるのは楽。直感的な並び替えをとるか、位置決めの楽さをとるか、悩みどころ。セクション末尾に自動生成のたすくま式が落とし所か。
code:js
// カーソル行のテキストを取得
const cursorRange = editor.getSelectedLineRange(); // カーソル行の範囲を取得
const cursorLineText = editor.getTextInRange(cursorRange0, cursorRange1); // カーソル行のテキストを取得
// 行頭の特定の記号とその後の時間パターンに一致する正規表現
const timePattern = /^\d{2}:\d{2}-\d{2}:\d{2}\s*/;
const symbolAndTimePattern = /^- \.*\\s*\d{2}:\d{2}-\d{2}:\d{2}\s*/;
const symbolPattern = /^- \.*\\s*/;
let newTask;
if (symbolAndTimePattern.test(cursorLineText)) {
// 記号と時間パターンがある場合、その部分を削除し、行頭に- [ ] を追加
newTask = '' + cursorLineText.replace(symbolAndTimePattern, '- ').trim();
} else if (symbolPattern.test(cursorLineText)) {
// 記号のみの場合、その記号を- [ ] に置き換える
newTask = '' + cursorLineText.replace(symbolPattern, '- ').trim();
} else {
// パターンがない場合、行頭に- [ ] を追加
newTask = '- ' + cursorLineText.trim();
}
// 現在のファイル名とカーソル位置を保存
const originalFileName = editor.getFileName();
const originalFolderPath = editor.getFolderPath();
const originalCursorPosition = editor.getSelectedRange(); // start, end
// リピートタスク.md のパスを定義
const repeatTaskFilePath = originalFolderPath + "/リピートタスク.md";
// リピートタスク.md の内容を取得し、リストとして表示
editor.openFile(repeatTaskFilePath, 'edit', function() {
const repeatTaskContent = editor.getText();
const taskList = repeatTaskContent.split('\n').filter(line => line.trim() !== '');
// リストとして表示し、追加位置を選択
ui.list('タスクを挿入する場所を選択してください', taskList, false, (selectedValues, selectedIndices) => {
if (selectedIndices !== undefined && selectedIndices.length > 0) {
const insertIndex = selectedIndices0 + 1; // 選択したタスクの下に挿入するため+1
// 新しいタスクを選択した位置の下に挿入
taskList.splice(insertIndex, 0, newTask);
const updatedContent = taskList.join('\n');
// リピートタスク.md の内容を更新
editor.setText(updatedContent);
ui.hudSuccess("リピートタスクに追加されました。");
} else {
ui.hudError("タスクの挿入がキャンセルされました。");
}
// 元のノートに戻り、カーソル位置を復元
const originalNotePath = ${originalFolderPath}/${originalFileName};
editor.openFile(originalNotePath, 'edit', function() {
editor.setSelectedRange(originalCursorPosition0, originalCursorPosition1);
});
});
});